<template>
 <el-form
      ref="formRef"
      :model="formData"
      :rules="formRules"
      label-width="150px"
      v-loading="formLoading"
    >
    <card-title title="基本设置"/>
    <el-form-item label="答对一题奖励" prop="rewardIntegral">
        <el-input v-model="formData.rewardIntegral" placeholder="请输入答对一题奖励积分数量"  clearable>
          <template #append>积分</template>
        </el-input>
      </el-form-item>
      <el-form-item label="每日达标题量" prop="standard">
        <el-input v-model="formData.standard" placeholder="请输入每日答题达标数量" clearable/>
      </el-form-item>
      <el-form-item label="题库体验题数" prop="freepoolnum">
        <el-input v-model="formData.freepoolnum" placeholder="请输入题库体验题数" clearable/>
      </el-form-item>
   <el-form-item label="知识点体验章数" prop="freeknowledgenum">
        <el-input v-model="formData.freeknowledgenum" placeholder="请输入知识点体验章数" clearable/>
      </el-form-item>
      <el-form-item label="轮播图高度" prop="bannerHeight">
        <el-input v-model="formData.bannerHeight" placeholder="请输入轮播图高" clearable/>
      </el-form-item>
<card-title title="支付设置"/>
      <el-form-item label="支付开启" prop="payOpen" >
        <el-radio-group v-model="formData.payOpen">
          <el-radio
            v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
            :key="dict.value"
            :label="dict.value"
          >
            {{ dict.label }}
          </el-radio>
        </el-radio-group>
      </el-form-item>
       <el-form-item label="IOS支付" prop="ios">
        <el-radio-group v-model="formData.ios">
          <el-radio
            v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
            :key="dict.value"
            :label="dict.value"
          >
            {{ dict.label }}
          </el-radio>
        </el-radio-group>
      </el-form-item>
<card-title title="智能考试试卷设置"/>
      <el-form-item label="题型设置" v-if="formData.franction">
   <div v-for="(item,index) in getStrDictOptions(DICT_TYPE.EXAM_TEST_TYPE)" :key="index" class="flex mb-10px w-1/1">
        <div>{{item.label}} 包含:</div>
        <el-input class="flex-1" v-model="formData.franction[item.value]['num']" placeholder="请输入数量" clearable/> <div>道&nbsp;&nbsp;</div>
        <div>每题:</div>
        <el-input  class="flex-1"  v-model="formData.franction[item.value]['score']" placeholder="请输入分数" clearable/><div>分&nbsp;&nbsp;</div>
        <div>题库{{item.label}}共1道</div>
   </div>
      </el-form-item>
 <el-form-item label="考试时长单位(分)" prop="paperTime">
        <el-date-picker
          v-model="formData.paperTime"
          type="date"
          value-format="x"
          placeholder="选择考试时长单位(分)" clearable
        />
      </el-form-item>
<el-form-item label="及格分数" prop="pass">
        <el-input v-model="formData.pass" placeholder="请输入及格分数" clearable/>
      </el-form-item>
      <el-form-item label="良好分数" prop="good">
        <el-input v-model="formData.good" placeholder="请输入良好分数" clearable/>
      </el-form-item>
      <el-form-item label="优异分数" prop="excellent">
        <el-input v-model="formData.excellent" placeholder="请输入优异分数" clearable/>
      </el-form-item>

      <card-title title="分享设置"/>
   <el-form-item label="每次分享可得积分" prop="shareIntegral">
        <el-input v-model="formData.shareIntegral" placeholder="请输入每次分享可得积分" clearable/>
      </el-form-item>
      <el-form-item label="每日分享积分上限" prop="shareupper">
        <el-input v-model="formData.shareupper" placeholder="请输入每日分享获得积分上限" clearable/>
      </el-form-item>
      <el-form-item label="分享标题" prop="shareTitle">
        <el-input v-model="formData.shareTitle" placeholder="请输入分享标题" clearable/>
      </el-form-item>
<card-title title="公告设置"/>      
      <el-form-item label="公告是否显示" prop="isDisplay">
        <el-radio-group v-model="formData.isDisplay">
          <el-radio
            v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
            :key="dict.value"
            :label="dict.value"
          >
            {{ dict.label }}
          </el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="显示条数" prop="displayNum">
        <el-input v-model="formData.displayNum" placeholder="请输入公告显示条数" clearable/>
      </el-form-item>
<el-form-item label="是否必须完善信息" prop="infoStatus">
        <el-radio-group v-model="formData.infoStatus">
          <el-radio
            v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
            :key="dict.value"
            :label="dict.value"
          >
            {{ dict.label }}
          </el-radio>
        </el-radio-group>
      </el-form-item>
      <card-title title="倒计时管理"/>
  <el-form-item label="倒计时显示" prop="timeDisplay">
        <el-radio-group v-model="formData.timeDisplay">
          <el-radio
            v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
            :key="dict.value"
            :label="dict.value"
          >
            {{ dict.label }}
          </el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="倒计时事件名称" prop="countdown">
        <el-input v-model="formData.countdown" placeholder="请输入倒计时事件名称" clearable/>
      </el-form-item>
      <el-form-item label="时间点" prop="countdowntime">
        <el-date-picker
          v-model="formData.countdowntime"
          type="date"
          value-format="x"
          placeholder="选择时间点" clearable
        />
      </el-form-item>



      <el-form-item label="高频题积分个数" prop="useIntegralNum">
        <el-input v-model="formData.useIntegralNum" placeholder="请输入高频题消耗积分个数" clearable/>
      </el-form-item>
      <el-form-item label="勋章设置" prop="medal">
        <el-input v-model="formData.medal" placeholder="请输入勋章设置" clearable/>
      </el-form-item>
  
      <el-form-item label="官方微信号" prop="wechatNumber">
        <el-input v-model="formData.wechatNumber" placeholder="请输入官方微信号" clearable/>
      </el-form-item>

     

      <el-form-item label="学生开启" prop="studentOpen">
        <el-radio-group v-model="formData.studentOpen">
          <el-radio
            v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
            :key="dict.value"
            :label="dict.value"
          >
            {{ dict.label }}
          </el-radio>
        </el-radio-group>
      </el-form-item>

      <el-form-item label="状态" prop="status">
        <el-radio-group v-model="formData.status">
          <el-radio
            v-for="dict in getIntDictOptions(DICT_TYPE.COMMON_STATUS)"
            :key="dict.value"
            :label="dict.value"
          >
            {{ dict.label }}
          </el-radio>
        </el-radio-group>
      </el-form-item>
    </el-form>


</template>
<script setup lang="ts">
import { getIntDictOptions,getStrDictOptions, DICT_TYPE } from '@/utils/dict'
/** 基础设置 表单 */
defineOptions({ name: 'SettingForm' })

const { t } = useI18n() // 国际化
const message = useMessage() // 消息弹窗
const props = defineProps({
  formData: {
    type: Object,
    default: () => {}
  }
})
const formData=ref(props.formData)
watch(() => props.formData, (val) => {
  formData.value = val
  if(formData.value.franction){
    formData.value.franction=JSON.parse(formData.value.franction)
  }else{
    formData.value.franction={}
    getStrDictOptions(DICT_TYPE.EXAM_TEST_TYPE).forEach((item)=>{
      formData.value.franction[item.value+'']={
        num:0,
        score:0
      }
    })
  }
  console.log(formData.value)
})
const formRules = reactive({
  infoStatus: [{ required: true, message: '是否必须完善信息', trigger: 'blur' }],
  ios: [{ required: true, message: 'IOS支付开启关闭不能为空', trigger: 'blur' }],
  status: [{ required: true, message: '状态不能为空', trigger: 'blur' }]
})
const formRef = ref()
const validateForm=async()=>{
  return formRef.value.validate()
}
defineExpose({ validateForm })
</script>